package leetcode.editor.cn;

public class P338CountingBits {
    public static void main(String[] args) {
        Solution solution = new P338CountingBits().new Solution();
        solution.countBits(5);

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int[] countBits(int n) {
            int[] arr = new int[n + 1];
            for (int i = 0; i <= n; i++) {
                int temp = i;
                int count = 0;
                while (temp != 0) {
                    int remain = temp % 2;
                    temp = temp / 2;
                    if (remain == 1) {
                        count++;
                    }
                }
                System.out.println(count);
                arr[i] = count;
            }
            return arr;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}